import { createSlice } from "@reduxjs/toolkit";

const userStore = createSlice({
  name: "user",
  /*
    初始化状态
    @login: boolean false未登录，true已登录
  */
  initialState: {
    userInfo: {
      id: "",
      account: "",
      password: "",
      name: "",
      token: "",
    },
    login: false,
  },
  //   修改状态（同步）
  reducers: {
    setUser(state, action) {
      state.userInfo = action.payload;
    },
    setLogin(state, action) {
      state.login = action.payload;
    },
  },
});

const { setUser, setLogin } = userStore.actions;
const userReducer = userStore.reducer;
export { setUser, setLogin };
export default userReducer;
